﻿/*
* Copyright 2009-2010 AKABANA.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Akabana.Amf.Messaging
{
    /**
     * <summary>障害クラス</summary>
     * 
     */
    public class Fault
    {
        /**
         * <summary>障害生成する</summary>
         * <param Name="e">例外</param>
         * <returns>障害クラス</returns>
         */
        public static Fault CreateFault(System.Exception e)
        {
            var result = new Fault();
            System.Exception cause = e;
            while (cause.InnerException != null)
            {
                cause = cause.InnerException;
            }

            result.FaultDetail = cause.Message + "\r" + cause.StackTrace;
            result.FaultCode = cause.GetType().FullName;
            result.FaultString = cause.Message;
            result.RootCause = e.InnerException == null ? null : e.InnerException.Message + "\r" + e.InnerException.StackTrace;
            return result;
        }
        
        /**
         * <summary>障害コード</summary>
         * 
         */
        public string FaultCode { get; set; }

        /**
         * <summary>障害内容</summary>
         * 
         */
        public string FaultString { get; set; }

        /**
         * <summary>障害招待</summary>
         * 
         */
        public string FaultDetail { get; set; }

        /**
         * <summary>障害理由例外</summary>
         * 
         */
        public string RootCause { get; set; }

    }
}
